<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('接口编排')"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <link th:href="@{/css/common.css}" rel="stylesheet"/>
    <link th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/process_arrangement.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
<input type="hidden" name="interfaceId" th:value="${interfaceId}">
<!--记录当前操作的流程分支id -->
<input type="hidden" name="processBranchId"/>
<input type="hidden" name="parentProcessBranchId"/>
<input type="hidden" name="sortNum"/>
<input type="hidden" name="processBranchName"/>
<input type="hidden" name="processBranchType"/>
<input type="hidden" name="outSortNum"/>
<div class="wrapper wrapper-content ">
    <div class="header">
        <h4 class="fz16">流程分支编排</h4>
    </div>
    <div class="content">
        <div class="content-box left-part pull-left">
            <ul class="nav nav-tabs navtabs" role="tablist">
                <li class="active"><a href="#byProcessBranchName" role="tab" data-toggle="tab"
                                      data-action="queryProcessBranch">按接口名</a></li>
                <li><a href="#byProcessBranchStory" role="tab" data-toggle="tab" data-action="queryProcessBranchStory">按步骤故事</a>
                </li>
                <li class="checkbox-slider">
                    <div style="margin-right: 5px;">只看流程条件</div>
                    <div class="checkbox checkbox-slider--b-flat">
                        <label>
                            <input type="checkbox" class="check-process-condition"><span></span>
                        </label>
                    </div>
                    <div class="ellipsis">
                        <a tabindex="0"
                           role="button"
                           data-toggle="popover"
                           data-container="body"
                           data-placement="auto bottom"
                           data-content="
									 <ul>
										 <li class='process-conditions-if' processBranchType='if'>设主流程条件</li>
										 <li class = 'process-conditions-virtualUsage'>新增虚拟用况</li>
										 <li class = 'process-conditions-virtualUsageGroup'>新增虚拟用况组</li>
									 </ul>
                               ">
                            <img th:src="@{/img/Icon-ellipsis.png}">
                        </a>
                    </div>
                    <a class="add-popover-tit  process-conditions-if" processBranchType='if' style="color: #0088FF;cursor: pointer;" >
                        <i class="fa fa-plus" style="margin-right: 5px;"></i>设主流程条件
					</a>
                </li>
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="byProcessBranchName">
                    <div class="tree well">
                        <ul>
                            <li>
                                <ul id="treeRootByName"></ul>
                            </li>
                        </ul>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="byProcessBranchStory">
                    <div class="tree well">
                        <ul>
                            <li>
                                <ul id="treeRootByStory"></ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="content-box right-part pull-left">
            <div class="title"></div>
            <dl class="dl-horizontal">
                <dt>业务描述</dt>
                <dd>
                </dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>开发逻辑</dt>
                <dd>
                </dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>出入参映射</dt>
                <dd>
                </dd>
            </dl>
        </div>
    </div>
</div>
<div class="modal inmodal fade" id="updateVirtualUsageAlisaName" tabindex="-1" role="dialog" aria-hidden="true">
    <input type="hidden" name="preProcessBranchId"/>
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title pull-left">添加虚拟用况别名</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="VirtualUsageAlisaNameForm">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">虚拟用况别名</label>
                        <div class="col-sm-8">
                            <input class="form-control" name="updateAlisaName" type="text" placeholder="虚拟用况别名">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-success" onclick="saveVirtualUsageAlisaName()">确定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal fade" id="addVirtualUsage" tabindex="-1" role="dialog" aria-hidden="true">
    <input type="hidden" name="preProcessBranchId"/>
    <input type="hidden" name="addVirtualUsageType"/>
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title pull-left">添加虚拟用况</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="commentForm">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">虚拟用况</label>
                        <div class="col-sm-8">
                            <div class="dropdown bootstrap-select form-control noselect2 bs3"
                                 id="virtualUsageList"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">父级结点</label>
                        <div class="col-sm-8">
                            <input class="form-control" name="modelProcessBranchName" type="text"
                                   placeholder="虚拟用况名称/分支流程名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">虚拟用况别名</label>
                        <div class="col-sm-8">
                            <input class="form-control" name="alisaName" type="text" placeholder="虚拟用况别名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">设为流程结束</label>
                        <div class="col-sm-8">
                            <div class="checkbox checkbox-slider--b-flat" style="margin-top: 7px;">
                                <label>
                                    <input type="checkbox" class="process-end"><span></span>
                                </label>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-success" onclick="saveVirtualUsage(1)">确定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal fade" id="addVirtualUsageGroup" tabindex="-1" role="dialog" aria-hidden="true">
    <input type="hidden" name="preProcessBranchId"/>
    <input type="hidden" name="addVirtualUsageGroupType"/>
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title pull-left">添加虚拟用况组</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">虚拟用况组</label>
                        <div class="col-sm-8">
                            <div class="dropdown bootstrap-select form-control noselect2 bs3" id="virtualUsageGroupList"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">父级结点</label>
                        <div class="col-sm-8">
                            <input class="form-control" name="modelProcessBranchName" type="text" placeholder="虚拟用况组名称/分支流程名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">虚拟用况组别名</label>
                        <div class="col-sm-8">
                            <input class="form-control" name="groupAlisaName" type="text" placeholder="虚拟用况组别名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">设为流程结束</label>
                        <div class="col-sm-8">
                            <div class="checkbox checkbox-slider--b-flat" style="margin-top: 7px;">
                                <label>
                                    <input type="checkbox" class="process-end"><span></span>
                                </label>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-success" onclick="saveVirtualUsage(4)">确定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal fade process-conditions-model" id="processConditions" tabindex="-1" role="dialog"
     aria-hidden="false">
    <input type="hidden" name="modalProcessBranchId"/>
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title pull-left">设分支流程条件</h4>
            </div>
            <div class="modal-body">
                <div class="tab-content">
                    <div role="tabpanel" class="tab-pane active">
                        <table class="table" id="conditionTable">
                            <thead>
                            <tr>
                                <th></th>
                                <th>序号</th>
                                <th>模式名</th>
                                <th>分组</th>
                                <th>接口</th>
                                <th>对象类型</th>
                                <th>判断条件</th>
                                <th>约定值</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div onclick="addCondition()"><i class="fa fa-plus" style="margin-right: 5px;"></i>新增条件</div>
                <textarea placeholder="输入需求故事描述" class="branchConditionDesc"></textarea>
                <div class="checkbox-p">
                    <span class="pull-left">设为异常结束</span>
                    <div class="checkbox checkbox-slider--b-flat pull-left " style="margin-top: 0px;margin-left: 10px;">
                        <label>
                            <input type="checkbox" class="processEndFlag"><span></span>
                        </label>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div>
                    <span class="pull-left">条件公式</span>
                    <select class="form-control join-condition">
                        <option value="and" selected="selected">AND</option>
                        <option value="or">OR</option>
                    </select>
                </div>
                <div class="groupList"></div>
                <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-success process-conditions-ifOrElseIf-save">确定</button>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-select-js"/>
<script id="virtualUsageListTpl" type="text/template">
    <select name="virtualUsageId" id="virtualUsageId" class="form-control noselect2 selectpicker" title="请选择"
            tabindex="-98">
        {{# layui.each(d, function(index, a){ }}
        <option value="{{a.id}}">{{a.slaveInterfaceName}}</option>
        {{# }); }}
    </select>
</script>
<script id="virtualUsageGroupListTpl" type="text/template">
    <select name="virtualUsageGroupId" id="virtualUsageGroupId" class="form-control noselect2 selectpicker" title="请选择" tabindex="-98">
        {{# layui.each(d, function(index, a){ }}
            <option value="{{a.id}}">{{a.groupName}}</option>
        {{# }); }}
    </select>
</script>
<script id="processBranchNodeByNameTpl" type="text/html">
    <li data-color="{{d.color}}" data-desc="{{d.processBranchName}}" data-id="{{d.processBranchId}}"
        style="cursor: {{# if(!(d.color=='green' || d.processBranchName=='else')){ }}pointer{{# }else{ }}default{{# } }};">
        <div>
            <span class="badge badge-primary bg-{{d.color}} expand-children" data-id="{{d.processBranchId}}">{{d.index}}</span>
            <span class="content-txt">{{d.processBranchNameDom}}</span>
            <a class="show-popover"
               data-id="{{d.processBranchId}}"
               data-pid="{{d.parentProcessBranchId}}"
               data-sortnum="{{d.sortNum}}"
               tabindex="0"
               role="button"
               data-toggle="popover"
               data-container="body"
               data-content="
                              {{# if(d.color=='yellow' && d.processBranchName=='else'){ }}
                                <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' sortNum = '{{d.sortNum}}'>
                                    <li class='process-conditions-end-if-elseif-else'>设流程结束</li>
                                    <li class='process-conditions-else-error-no-else'>设流程异常结束</li>
                                    <li class='process-conditions-virtualUsage'>新增虚拟用况</li>
									<li class='process-conditions-virtualUsage' type='out'>新增虚拟用况（外）</li>
									<li class='process-conditions-virtualUsageGroup'>新增虚拟用况组</li>
									<li class='process-conditions-virtualUsageGroup' type='out'>新增虚拟用况组（外）</li>
                                    <li class='process-conditions-outOfCycle-if-elseif-else'>跳出循环分支</li>
                                    <li class='process-conditions-continueCycle-if-elseif-else'>继续循环分支</li>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
                             {{# } else if(d.color=='yellow'){ }}
                                <ul id='{{d.processBranchId}}'pid = '{{d.parentProcessBranchId}}' sortNum = '{{d.sortNum}}'>
                                    <li class='process-conditions-else'>设分支流程条件</li>
                                    <li class='process-conditions-elseif' processBranchType='elseif'>设异常流程条件</li>
                                    <li class='process-conditions-else-error'>设异常结束条件</li>
                                    <li class='process-conditions-end-if-elseif-else'>设流程结束</li>
                                    <li class='process-conditions-else-error-no-else'>设流程异常结束</li>
                                    <li class='process-conditions-virtualUsage'>新增虚拟用况</li>
									<li class='process-conditions-virtualUsage' type='out'>新增虚拟用况（外）</li>
									<li class='process-conditions-virtualUsageGroup'>新增虚拟用况组</li>
									<li class='process-conditions-virtualUsageGroup' type='out'>新增虚拟用况组（外）</li>
                                    <li class='process-conditions-outOfCycle-if-elseif-else'>跳出循环分支</li>
                                    <li class='process-conditions-continueCycle-if-elseif-else'>继续循环分支</li>
                                    <li class='process-conditions-update'>编辑</li>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
                            {{# } else if(d.color=='purple'){ }}
                                <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' virtualUsageGroupId = '{{d.entityId}}' description='{{d.processBranchName}}'>
                                    <li class='process-conditions-if' processBranchType='if'>设主流程条件</li>
                                    <li class='process-conditions-end'>设流程结束</li>
                                    <li class='process-conditions-bffUsageGroupParam'>设字段来源</li>
                                    <li class='process-conditions-virtualUsage' color='{{d.color}}'>新增虚拟用况</li>
                                    <li class='process-conditions-virtualUsageGroup' color='{{d.color}}'>新增虚拟用况组</li>
                                    <li class='process-conditions-outOfCycle'>跳出循环分支</li>
                                    <li class='process-conditions-continueCycle'>继续循环分支</li>
                                    <li class='process-conditions-virtualUsageGroup-update'>编辑</li>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
                             {{# } else if(d.color=='blue'){ }}
                                <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' virtualUsageId = '{{d.entityId}}' description='{{d.processBranchName}}'>
                                    <li class='process-conditions-if' processBranchType='if'>设主流程条件</li>
                                    <li class='process-conditions-end'>设流程结束</li>
                                    <li class='process-conditions-bffUsageParam'>设字段来源</li>
                                    <li class='process-conditions-virtualUsage' color='{{d.color}}'>新增虚拟用况</li>
                                    <li class='process-conditions-virtualUsageGroup' color='{{d.color}}'>新增虚拟用况组</li>
                                    <li class='process-conditions-outOfCycle'>跳出循环分支</li>
                                    <li class='process-conditions-continueCycle'>继续循环分支</li>
                                    <li class='process-conditions-virtualUsage-update'>编辑</li>
                                    <li class='process-conditions-virtualUsageAliasName-update'>编辑虚拟用况别名</li>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
                             {{# } else if(d.color=='green'|| d.color=='yellow2' || d.color=='yellow3'){ }}
                                <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}'>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
                            {{# } else if(d.color=='red'){ }}
                                <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' entityid='{{d.entityId}}' >
                                    <li class='set-error-code'>设错误码</li>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
                             {{# } }}"
               data-placement="auto bottom"
            >
                <img class="pull-right" th:src="@{/img/Icon-ellipsis.png}">
            </a>
        </div>
        {{# if(d.children.length > 0){ }}
        <ul class="childList{{d.processBranchId}}"></ul>
        {{# } }}
    </li>
</script>
<script id="processBranchNodeByStoryTpl" type="text/html">
    <li data-color="{{d.color}}" data-desc="{{d.processBranchName}}" data-id="{{d.processBranchId}}"
        style="cursor: {{# if(!(d.color=='green' || d.processBranchName=='else')){ }}pointer{{# }else{ }}default{{# } }};">
        <div>
            <span class="badge badge-primary bg-{{d.color}} expand-children" data-id="{{d.processBranchId}}">{{d.index}}</span>
            <span class="content-txt">{{d.processBranchDescription}}</span>
            {{# if(d.pointColor !='' && d.pointColor != null){ }}
            <i class="flag {{d.pointColor}}"></i>
            {{# } }}
            <a class="show-popover"
               data-id="{{d.processBranchId}}"
               data-pid="{{d.parentProcessBranchId}}"
               data-sortnum="{{d.sortNum}}"
               tabindex="0"
               role="button"
               data-toggle="popover"
               data-container="body"
               data-placement="auto bottom"
               data-content="
								 {{# if(d.color=='yellow' && d.processBranchName=='else'){ }}
									<ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}'>
									    <li class='process-conditions-end-if-elseif-else'>设流程结束</li>
										<li class='process-conditions-else-error-no-else'>设流程异常结束</li>
										<li class='process-conditions-virtualUsage'>新增虚拟用况</li>
										<li class='process-conditions-virtualUsageGroup'>新增虚拟用况组</li>
										<li class='process-conditions-outOfCycle-if-elseif-else'>跳出循环分支</li>
										<li class='process-conditions-continueCycle-if-elseif-else'>继续循环分支</li>
										<li class='process-conditions-delete'>删除</li>
									</ul>
								 {{# } else if(d.color=='yellow'){ }}
									<ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' sortNum = '{{d.sortNum}}'>
										<li class='process-conditions-else'>设分支流程条件</li>
										<li class='process-conditions-elseif' processBranchType='elseif'>设异常流程条件</li>
										<li class='process-conditions-else-error'>设异常结束条件</li>
										<li class='process-conditions-end-if-elseif-else'>设流程结束</li>
										<li class='process-conditions-else-error-no-else'>设流程异常结束</li>
										<li class='process-conditions-virtualUsage'>新增虚拟用况</li>
										<li class='process-conditions-virtualUsage' type='out'>新增虚拟用况（外）</li>
										<li class='process-conditions-virtualUsageGroup'>新增虚拟用况组</li>
										<li class='process-conditions-virtualUsageGroup' type='out'>新增虚拟用况组（外）</li>
										<li class='process-conditions-outOfCycle-if-elseif-else'>跳出循环分支</li>
										<li class='process-conditions-continueCycle-if-elseif-else'>继续循环分支</li>
										<li class='process-conditions-update'>编辑</li>
										<li class='process-conditions-delete'>删除</li>
									</ul>
                                {{# } else if(d.color=='purple'){ }}
                                    <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' virtualUsageGroupId = '{{d.entityId}}' description='{{d.processBranchName}}'>
                                        <li class='process-conditions-if' processBranchType='if'>设主流程条件</li>
                                        <li class='process-conditions-end'>设流程结束</li>
                                        <li class='process-conditions-bffUsageGroupParam'>设字段来源</li>
                                        <li class='process-conditions-virtualUsage' color='{{d.color}}'>新增虚拟用况</li>
                                        <li class='process-conditions-virtualUsageGroup' color='{{d.color}}'>新增虚拟用况组</li>
                                        <li class='process-conditions-outOfCycle'>跳出循环分支</li>
                                        <li class='process-conditions-continueCycle'>继续循环分支</li>
                                        <li class='process-conditions-virtualUsageGroup-update'>编辑</li>
                                        <li class='process-conditions-delete'>删除</li>
                                    </ul>
								 {{# } else if(d.color=='blue'){ }}
									<ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' virtualUsageId = '{{d.entityId}}' description='{{d.processBranchName}}'>
										<li class='process-conditions-if' processBranchType='if'>设主流程条件</li>
										<li class='process-conditions-end'>设流程结束</li>
										<li class='process-conditions-bffUsageParam'>设字段来源</li>
										<li class='process-conditions-virtualUsage' color='{{d.color}}'>新增虚拟用况</li>
										<li class='process-conditions-virtualUsageGroup' color='{{d.color}}'>新增虚拟用况组</li>
										<li class='process-conditions-outOfCycle'>跳出循环分支</li>
										<li class='process-conditions-continueCycle'>继续循环分支</li>
										<li class='process-conditions-virtualUsage-update'>编辑</li>
										<li class='process-conditions-virtualUsageAliasName-update'>编辑虚拟用况别名</li>
										<li class='process-conditions-delete'>删除</li>
									</ul>
								 {{# } else if(d.color=='green'|| d.color=='yellow2'|| d.color=='yellow3'){ }}
                                <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}'>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
                              {{# } else if(d.color=='red'){ }}
                                <ul id='{{d.processBranchId}}' pid = '{{d.parentProcessBranchId}}' entityid='{{d.entityId}}' >
                                    <li class='set-error-code'>设错误码</li>
                                    <li class='process-conditions-delete'>删除</li>
                                </ul>
								 {{# } }}"
            >
                <img class="pull-right" th:src="@{/img/Icon-ellipsis.png}">
            </a>
        </div>
        {{# if(d.children.length > 0){ }}
        <ul class="childList{{d.processBranchId}}"></ul>
        {{# } }}
    </li>
</script>
<script id="addConditionTpl" type="text/html">
    <tr>
        <td class="delCondition"><img th:src="@{/img/Icon-jianshao.png}" class="icon-jian"></td>
        <td>1</td>
        <td>
            <select class="form-control branchConditionDetailDictCode-select" name="branchConditionDetailDictCode">
                <option value="1" selected="selected">字段</option>
                <option value="2">数据集条数</option>
                <option value="3">出参</option>
            </select>
        </td>
        <td>
            <select class="form-control group-select">
                {{# layui.each(groupList, function(index, a){ }}
                    <option value="{{a.key}}" {{#if(a.key=='1'){}}selected{{# }}}>{{a.name}}</option>
                {{# }); }}
            </select>
        </td>
        <td>
            <select class="form-control interface-select">
				{{# layui.each(d.interfaceList, function(index, a){ }}
				<option value="{{a.interfaceId}}"
                        data-interfacetype="{{a.interfaceType}}"
                        data-objectprocessbranchid="{{a.objectProcessBranchId}}"
                >{{a.interfaceName}}</option>
				{{# }); }}
            </select>
        </td>
        <td style="display: flex">
            <select class="form-control obj1-select">
                <option value="0" selected="selected">--请选择--</option>
                <option value="1">字段</option>
                <option value="2" style="display: none">数据集</option>
                <option value="3">数据集字段</option>
            </select>
            <div class="ObjSelect" style="display: flex"></div>
        </td>
        <td>
            <select class="form-control condition-select">
                {{# layui.each(d.conditionDictList, function(index, a){ }}
                <option value="{{a.dictValue}}">{{a.dictLabel}}</option>
                {{# }); }}
            </select>
        </td>
        <td class="contractValueTd">
            <div style="display: flex" class="contractValue">
                <select class="form-control dictCategory-select" style="width: 150px">
                    <option value="">--请选择--</option>
                    {{# layui.each(d.dictCategoryList, function(index, a){ }}
                    <option value="{{a.dictValue}}">{{a.dictLabel}}</option>
                    {{# }); }}
                </select>
            </div>
        </td>
    </tr>
</script>
<script id="groupInfoTpl" type="text/html">
    {{# layui.each(d, function(index, a){ }}
    <div class="dashed-p">
        <span class="pull-left">组{{a.branchConditionGroupId}}</span>
        <select class="form-control select-group{{a.branchConditionGroupId}} branchCondition" data-id="{{a.branchConditionGroupId}}">
            <option value="and" {{#if(a.joinCondition=='and'){}}selected{{# }}}>AND</option>
            <option value="or" {{#if(a.joinCondition=='or'){}}selected{{# }}}>OR</option>
        </select>
    </div>
    {{# }); }}
</script>
<script id="selectTpl" type="text/html">
    <select class="form-control obj{{d.prefix}}-select" data-type="{{d.type||''}}">
        <option value="0">--请选择--</option>
        {{# layui.each(d.data, function(index, a){ }}
            <option value="{{a.id}}"
                    data-objectid="{{a.objectProcessBranchId}}"
                    data-objectname="{{a.paramName}}"
                    data-isfieldenum="{{a.isFieldEnum}}"
                    data-dictid="{{a.dictId}}"
                    {{#if(a.id==d.selectId){}}selected{{# }}}
            >{{a.paramName}}
            </option>
        {{# }); }}
    </select>
</script>
<script id="selectFieldEnumTpl" type="text/html">
    <select class="form-control obj{{d.prefix||''}}-select contractValue-select" data-type="{{d.type||''}}">
        {{# layui.each(d.data, function(index, a){ }}
        <option value="{{a.dictValue}}" data-dictlabel="{{a.dictLabel}}" {{#if(a.dictValue==d.selectId){}}selected{{# }}}>{{a.dictLabel}}</option>
        {{# }); }}
    </select>
</script>
<script id="editConditionTpl" type="text/html">
    {{# layui.each(d.processBranchConditionDetailList, function(index, pd){ }}
    <tr>
        <td class="delCondition"><img th:src="@{/img/Icon-jianshao.png}" class="icon-jian"></td>
        <td>{{pd.sortNum}}</td>
        <td>
            <select class="form-control branchConditionDetailDictCode-select" name="branchConditionDetailDictCode">
                <option value="1" {{#if(1==pd.branchConditionDetailDictCode){}}selected{{# }}}>字段</option>
                <option value="2" {{#if(2==pd.branchConditionDetailDictCode){}}selected{{# }}}>数据集条数</option>
                <option value="3" {{#if(3==pd.branchConditionDetailDictCode){}}selected{{# }}}>出参</option>
            </select>
        </td>
        <td>
            <select class="form-control group-select {{pd.branchConditionGroupId}}">
                {{# layui.each(groupList, function(index, a){ }}
                    <option value="{{a.key}}" {{#if(a.key==pd.branchConditionGroupId){}}selected{{# }}}>{{a.name}}</option>
                {{# }); }}
            </select>
        </td>
        <td>
            <select class="form-control interface-select">
                {{# layui.each(d.interfaceList, function(index, a){ }}
                <option value="{{a.interfaceId}}"
                        data-interfacetype="{{a.interfaceType}}"
                        data-objectprocessbranchid="{{a.objectProcessBranchId}}"
                        {{#if(a.interfaceId==pd.interfaceId && a.objectProcessBranchId==pd.objectProcessBranchId){}}selected{{# }}}>{{a.interfaceName}}</option>
                {{# }); }}
            </select>
        </td>
        <td style="display: flex">
            <select class="form-control obj1-select">
                <option value="0" selected="selected">--请选择--</option>
                <option value="1" {{# if(1==pd.objectType){}}selected{{# }}}
                        style="display:{{pd.branchConditionDetailDictCode==1?'block':'none'}}"
                >字段</option>
                <option value="2" {{# if(2==pd.objectType){ }}selected{{# }}}
                        style="display:{{pd.branchConditionDetailDictCode==2?'block':'none'}}"
                >数据集</option>
                <option value="3" {{# if(3==pd.objectType){ }}selected{{# }}}
                        style="display:{{pd.branchConditionDetailDictCode==1?'block':'none'}}"
                >数据集字段</option>
            </select>
            <div class="ObjSelect" style="display: flex"></div>
        </td>
        <td>
            <select class="form-control condition-select">
                {{# layui.each(d.conditionDictList, function(index, a){ }}
                <option value="{{a.dictValue}}" {{#if(a.dictValue==pd.judgeConditionDictCode){}}selected{{# }}}>{{a.dictLabel}}</option>
                {{# }); }}
            </select>
        </td>
        <td class="contractValueTd">
            <div style="display: flex" class="contractValue">
                <select class="form-control dictCategory-select" style="width: 100px">
                    <option value="">--请选择--</option>
                    {{# layui.each(d.dictCategoryList, function(index, a){ }}
                    <option value="{{a.dictValue}}" {{# if(pd.contractDictCategory==a.dictValue){ }}selected{{# }}}>{{a.dictLabel}}</option>
                    {{# }); }}
                </select>
                {{# if(!pd.contractDictCategory && pd.contractValue){ }}
                <input class="form-control oldContractValue" value="{{pd.contractValue||''}}" disabled style="width:80px">
                {{# }}}
            </div>
        </td>
    </tr>
    {{# }); }}
</script>
<script id="rightPartTpl" type="text/html">
    <div class="title">{{d.branchConditionName || d.processBranchName||d.errorCode||''}}</div>
        <dl class="dl-horizontal">
        <dt>业务描述</dt>
        <dd>{{d.branchConditionDesc || d.processBranchDescription || d.errorCodeDetail||''}}
        </dd>
        </dl>
        <!--<dl class="dl-horizontal">-->
        <!--<dt>开发逻辑</dt>-->
        <!--<dd>-->
        <!--</dd>-->
        <!--</dl>-->
        {{# if(d.color == "blue"){ }}
            <dl class="dl-horizontal">
                <dt>出入参映射</dt>
                {{# layui.each(d.fieldSourceVoList, function(index, a){ }}
                    <dd style = "margin-top:10px;">{{index + 1}}.{{a.mappingDesc}}</dd>
                {{# }); }}
            </dl>
        {{# }}}
        <div id="content-preview"></div>
    </div>
</script>
<!--关联字段模板-->
<script id="contentPreviewTpl" type="text/template">
    <div class="panel-body" style = "border:0px;padding: 0px">
        <div class="panel-tit">参数</div>
        <ul class="list-group">
            <li class="list-group-item" style="height: auto; padding-top:0px;">
                <div class="re-body">
                    <p>requestBody：//输入参数</p>
                    <p>{</p>
                    <ul class="list-group field">
                    {{# layui.each(d.requestList, function(index, a){ }}
                    {{# if(a.children == null || a.children.length == 0){ }}
                    <li class="list-group-item">
                    {{# if(a.objectType=='2'){ }}
                        <p>"{{a.fieldEnName}}" : [{ // {{a.fieldName || '-'}}</p>
                                                <br>
                                                <p>}],</p>
                                                {{# } else { }}
                                                <p>"{{a.fieldEnName}}" : "{{a.mockData || '一'}}", // <span style="color: #FFA500; display: inline !important;">{{a.fieldName || '-'}}{{a.fieldEnumListName || ''}}</span></p>
                                                {{# } }}
                    </li>
                                            {{# } else { }}
                                            <li class="list-group-item">
                                                {{# if(a.children.length > 1){ }}
                                                <p>"{{a.fieldEnName}}" : [{ // {{a.fieldName || '一'}}</p>
                                                <ul class="list-group field">
                                                    {{# layui.each(a.children, function(index, b){ }}
                                                    <li class="list-group-item" style = "margin-left:10px;">
                                                        <p>"{{b.fieldEnName}}" : "{{b.mockData || '一'}}", // <span style="color: #FFA500; display: inline !important;">{{b.fieldName || '一'}}{{b.fieldEnumListName || ''}}</span></p>
                                                    </li>
                                                    {{# }); }}
                                                </ul>
                                                <p>}],</p>
                                                {{# } else { }}
                                                <p>"{{a.fieldEnName}}" : ["{{a.children[0].mockData || '一'}}"], // {{a.fieldName || '一'}}</p>
                                                {{# } }}
                                            </li>
                                            {{# }}}
                                            {{# }); }}
                                        </ul>
                                        <p>}</p>
                                    </div>
                                </li>
                                <li class="list-group-item space"></li>
                                <li class="list-group-item" style="height: auto;padding-top:0px;">
                                    <div class="re-body">
                                        <p>response：//返回参数</p>
                                        <p>{</p>
                                        <ul class="list-group field">
                                            <li class="list-group-item">
                                                <p>"errCode" : "1",<span style="color: red; display: inline !important;"> //返回状态（true/false）</span></p>
                                                <p>"message" : "获取成功",<span style="color: red; display: inline !important;"> //获取成功/获取失败</span></p>
                                                <p>"data" : { <span style="color: red; display: inline !important;"> //返回数据</span></p>
                                                <ul class="list-group field">
                                                    {{# layui.each(d.responseList, function(index, a){ }}
                                                    {{# if(a.children == null || a.children.length == 0){ }}
                                                    <li class="list-group-item">
                                                        {{# if(a.objectType=='2'){ }}
                                                        <p>"{{a.fieldEnName}}" : [{ // {{a.fieldName || '一'}}</p>
                                                        <p>}],</p>
                                                        {{# } else { }}
                                                        {{# if(a.fieldEnName == 'total' || a.fieldEnName == 'isLastPage' || a.fieldEnName == 'pages'){ }}
                                                        <p>"{{a.fieldEnName}}" : {{a.mockData}}, // <span style="color: #FFA500; display: inline !important;">{{a.fieldName || '一'}}{{a.fieldEnumListName || ''}}</span></p>
                                                        {{# } else { }}
                                                        <p>"{{a.fieldEnName}}" : "{{a.mockData || '一'}}", // <span style="color: #FFA500; display: inline !important;">{{a.fieldName || '一'}}{{a.fieldEnumListName || ''}}</span></p>
                                                        {{# } }}
                                                        {{# } }}
                                                    </li>
                                                    {{# } else { }}
                                                    <li class="list-group-item">
                                                        <p>"{{a.fieldEnName}}" : [{ // {{a.fieldName || '一'}}</p>
                                                        <ul class="list-group field">
                                                            {{# layui.each(a.children, function(index, b){ }}
                                                            {{# if(b.children == null || b.children.length == 0){ }}
                                                            <li class="list-group-item">
                                                                {{# if(b.objectType=='2'){ }}
                                                                <p>"{{b.fieldEnName}}" : [{ // {{b.fieldName || '一'}}</p>
                                                                <p>}],</p>
                                                                {{# } else { }}
                                                                <p>"{{b.fieldEnName}}" : "{{b.mockData || '一'}}", // <span style="color: #FFA500; display: inline !important;">{{b.fieldName || '一'}}{{b.fieldEnumListName || ''}}</span></p>
                                                                {{# } }}
                                                            </li>
                                                            {{# } else { }}
                                                            <li class="list-group-item">
                                                                <p>"{{b.fieldEnName}}" : [{ // {{b.fieldName || '一'}}</p>
                                                                <ul class="list-group field">
                                                                    {{# layui.each(b.children, function(index, c){ }}
                                                                    {{# if(c.children == null || c.children.length == 0){ }}
                                                                    <li class="list-group-item">
                                                                        {{# if(c.objectType=='2'){ }}
                                                                        <p>"{{c.fieldEnName}}" : [{ // {{c.fieldName || '一'}}</p>
                                                                        <p>}],</p>
                                                                        {{# } else { }}
                                                                        <p>"{{c.fieldEnName}}" : "{{c.mockData || '一'}}", // <span style="color: #FFA500; display: inline !important;">{{c.fieldName || '一'}}{{c.fieldEnumListName || ''}}</span></p>
                                                                        {{# } }}
                                                                    </li>
                                                                    {{# } else { }}
                                                                    <li class="list-group-item">
                                                                        <p>"{{c.fieldEnName}}" : [{ // {{c.fieldName || '一'}}</p>
                                                                        <ul class="list-group field">
                                                                            {{# layui.each(c.children, function(index, d){ }}
                                                                            {{# if(d.children == null || d.children.length == 0){ }}
                                                                            <li class="list-group-item">
                                                                                {{# if(d.objectType=='2'){ }}
                                                                                <p>"{{d.fieldEnName}}" : [{ // {{d.fieldName || '一'}}</p>
                                                                                <p>}],</p>
                                                                                {{# } else { }}
                                                                                <p>"{{d.fieldEnName}}" : "{{d.mockData || '一'}}", // <span style="color: #FFA500; display: inline !important;">{{d.fieldName || '一'}}{{d.fieldEnumListName || ''}}</span></p>
                                                                                {{# } }}
                                                                            </li>
                                                                            {{# } else { }}
                                                                            <li class="list-group-item">
                                                                                <p>"{{d.fieldEnName}}" : [{ // {{d.fieldName || '一'}}</p>
                                                                                <ul class="list-group field">
                                                                                    {{# layui.each(d.children, function(index, e){ }}
                                                                                    <li class="list-group-item">
                                                                                        <p>"{{e.fieldEnName}}" : "{{e.mockData || '一'}}", // <span style="color: #FFA500; display: inline !important;">{{e.fieldName || '一'}}{{e.fieldEnumListName || ''}}</span></p>
                                                                                    </li>
                                                                                    {{# }); }}
                                                                                </ul>
                                                                                <p>}],</p>
                                                                            </li>
                                                                            {{# } }}
                                                                            {{# }); }}
                                                                        </ul>
                                                                    </li>
                                                                    {{# } }}
                                                                    {{# }); }}
                                                                </ul>
                                                                <p>}],</p>
                                                            </li>
                                                            {{# } }}
                                                            {{# }); }}
                                                        </ul>
                                                        <p>}],</p>
                                                    </li>
                                                    {{# }}}
                                                    {{# }); }}
                                                </ul>
                                                <p>}</p>
                                            </li>
                                        </ul>
                                        <p>}</p>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>
<script id="queryDictTypeOptionTpl" type="text/template">
    <select  name="dictType" class="form-control dictType-select" style="width: 100px">
        <option value="0">--选择字典类型--</option>
        {{# layui.each(d.data, function(index, a){ }}
        <option value="{{a.dictType}}"  {{# if(d.contractDictType==a.dictType){ }}selected{{# }}}>{{a.dictName}}</option>
        {{# }); }}
    </select>
</script>
<script id="queryDictOptionTpl" type="text/template">
    <select  class="form-control contractValue-select" style="width: 100px">
        <option value="0">--请选择--</option>
        {{# layui.each(d.data, function(index, a){ }}
        <option value="{{a.dictValue}}" {{# if(d.contractValue==a.dictValue){ }}selected{{# }}}>{{a.dictLabel}}</option>
        {{# }); }}
    </select>
</script>
<script type="text/javascript">
    var prefix = ctx + "processBranch/processBranch";
    // 默认家口id
    var interfaceId = $("input[name='interfaceId']").val();
    // 接口虚拟用况集合
    var virtualUsageList = [];
    // 接口虚拟用况集合
    var virtualUsageGroupList = [];
    // 条件列表获取
    var conditionDictList = [];
    // 接口列表获取
	var interfaceList = [];
	var popoverView = null;
	var noContractValues = ['IS_NULL','IS_NOT_NULL','IS_TRUE','IS_FALSE'];
	var groupSelectedList = [];
    // modal初始化
    var addVirtualUsageModal = $("#addVirtualUsage").prop("outerHTML");
    var addVirtualUsageGroupModal = $("#addVirtualUsageGroup").prop("outerHTML");
    var processConditionsModal = $("#processConditions").prop("outerHTML");
    var groupList=[
        {key:'1',name:'组1'},
        {key:'2',name:'组2'},
        {key:'3',name:'组3'},
        {key:'4',name:'组4'},
        {key:'5',name:'组5'},
        {key:'6',name:'组6'},
        {key:'7',name:'组7'},
        {key:'8',name:'组8'},
        {key:'9',name:'组9'},
        {key:'10',name:'组10'},
    ]
    /**
     * 初始化加载
     * 1.流程分之树,默认按接口名称
     * 2.查询接口虚拟用况
     * 3.条件列表获取
     */
    $(function () {
        queryProcessBranch();
        bffVirtualUsageList();
        bffVirtualUsageGroupList();
        getConditionDictList();
        getDictCategory();
    });

    /**
     * 页面全局事件处理
     * 1.
     * 2.按接口/步骤故事切换事件
     * 3.只看流程条件功能切换
     * 4.
     */
    $("body").on('click', ".process-conditions-if,.process-conditions-elseif,.process-conditions-update", function () {
        groupSelectedList = [];
        $('#processConditions').modal('show');
        $("#processConditions .modal-title").html($(this).html());
        $("input[name='processBranchType']").val($(this).attr('processBranchType'));
        if($(this).attr("class").indexOf("add-popover-tit") >= 0) {
            $("input[name='processBranchId']").val($(this).data("id"));
            $("input[name='parentProcessBranchId']").val($(this).data("pid"));
            $("input[name='sortNum']").val($(this).data("sortnum"));
            $("input[name='processBranchName']").val($(this).siblings(".content-txt").html());
        }
		queryInterfaceList();
		if($(this).attr("class") == 'process-conditions-update'){
			getProcessBranchDetail()
		}
    }).on('click', ".process-conditions-ifOrElseIf-save", function () {
        var processBranchCondition = {};
        processBranchCondition.type = $("input[name='processBranchType']").val();
        processBranchCondition.joinCondition = $(".join-condition").val();
        processBranchCondition.branchConditionDesc = $(".branchConditionDesc").val();
        var detailList = [];
        $("#conditionTable tbody>tr").each(function (i) {
            var detail = {};
            detail.branchConditionDetailDictCode = $(this).find("select[name='branchConditionDetailDictCode']").val();
            detail.branchConditionGroupId = $(this).find(".group-select").val();
            detail.objectCategory = $(this).find(".obj1-select").val() == 3 ? 2 : $(this).find(".obj1-select").val()
            detail.objectType = $(this).find(".obj1-select").val();
            detail.interfaceName = $(this).find(".interface-select option:selected").text();
            detail.interfaceId = $(this).find(".interface-select").val();
            detail.objectProcessBranchId = $(this).find(".interface-select option:selected").data("objectprocessbranchid");
            detail.objectId = $(this).find(".obj2-select").val();
            detail.objectName = $(this).find(".obj2-select option:selected").data("objectname");
            detail.objectFieldName = $(this).find(".obj3-select option:selected").text()=='--请选择--'?'':$(this).find(".obj3-select option:selected").text();
            detail.paramsId = $(this).find(".obj3-select option:selected").val()||'';
            detail.judgeConditionDictCode = $(this).find(".condition-select").val();
            detail.contractValue = $(this).find(".contractValue-select").val()||$(this).find(".oldContractValue").val()||'';
            detail.contractDictType = $(this).find(".dictType-select").val()||'';
            detail.contractDictCategory = $(this).find(".dictCategory-select").val()||'';
            detail.dictName = $(this).find(".contractValue-select option:selected").text();
            detail.joinCondition = $(".select-group" + detail.branchConditionGroupId).val()
            detail.sortNum = $(this).find("td:eq(1)").html();
            detailList.push(detail);
        });
        processBranchCondition.processBranchConditionDetailList = detailList;
        var parentProcessBranchId = $("input[name='parentProcessBranchId']").val();
        var processEndFlag = $('.processEndFlag').prop("checked") ? 'Y' : 'N';
        var sortNum = $("input[name='sortNum']").val();
        if (sortNum != null) {
            sortNum = parseInt(sortNum) + 1;
        }
        var params = {
            interfaceId: interfaceId,
            parentProcessBranchId: parentProcessBranchId,
            processEndFlag: processEndFlag,
            preProcessBranchId: $("input[name='processBranchId']").val(),
            sortNum: sortNum,
            processBranchCondition: processBranchCondition
        }
        //编辑处理
        var modalProcessBranchId = $("input[name='modalProcessBranchId']").val()
        modalProcessBranchId && (params.processBranchId = modalProcessBranchId);
        saveCondition(params);
    }).on('click', ".process-conditions-virtualUsage", function (e) {
        var processBranchName = $("input[name='processBranchName']").val()
        var preProcessBranchId ="";
        if ($(this).attr("color") == 'purple' || $(this).attr("color") == 'blue') {
            var currentProcessBranchId = $(this).parents("ul").attr("id")
            var parentLi = $("li[data-id='" + currentProcessBranchId + "']").parents("li");
            let {desc, id} = parentLi.data();
            processBranchName = desc;
            preProcessBranchId = id || currentProcessBranchId;
        }
        // 新增虚拟用况组（外）
        if($(this).attr("type")){
            preProcessBranchId = $(this).parents("ul").attr("pid");
            $("input[name='outSortNum']").val(parseInt($(this).parents("ul").attr("sortnum"))+1);
        }
        $("input[name='preProcessBranchId']").val(preProcessBranchId);

        $('#addVirtualUsage').modal('show');
        var virtualUsageListTplHtml = $("#virtualUsageListTpl").html();
        if (processBranchName) {
            $("input[name='modelProcessBranchName']").val(processBranchName.replace(/(<span class="specialFlag">|<\/span>)/g,''));
        }
        $("input[name='addVirtualUsageType']").val($(this).attr("type"));
        laytpl(virtualUsageListTplHtml).render(virtualUsageList || [], function (html) {
            $("#virtualUsageList").empty();
            $("#virtualUsageList").append(html);
            $('#virtualUsageId').selectpicker('refresh');
        });
    }).on('click', ".process-conditions-virtualUsageGroup", function (e) {
        var processBranchName = $("input[name='processBranchName']").val()
        var preProcessBranchId = "";
        console.log($(this).attr("type"));
        if ($(this).attr("color") == 'purple' || $(this).attr("color") == 'blue') {
            var currentProcessBranchId = $(this).parents("ul").attr("id")
            var parentLi = $("li[data-id='" + currentProcessBranchId + "']").parents("li");
            let {desc, id} = parentLi.data();
            processBranchName = desc;
            preProcessBranchId = id || currentProcessBranchId;
        }
        // 新增虚拟用况组（外）
        if($(this).attr("type")){
            preProcessBranchId = $(this).parents("ul").attr("pid");
        }
        $("input[name='preProcessBranchId']").val(preProcessBranchId)
        $('#addVirtualUsageGroup').modal('show');
        var virtualUsageGroupListTplHtml = $("#virtualUsageGroupListTpl").html();
        if (processBranchName) {
            $("input[name='modelProcessBranchName']").val(processBranchName.replace(/(<span class="specialFlag">|<\/span>)/g,''));
        }
        $("input[name='addVirtualUsageGroupType']").val($(this).attr("type"));
        laytpl(virtualUsageGroupListTplHtml).render(virtualUsageGroupList || [], function (html) {
            $("#virtualUsageGroupList").empty();
            $("#virtualUsageGroupList").append(html);
            $('#virtualUsageGroupId').selectpicker('refresh');
        });
    }).on('click', '.process-conditions-virtualUsageAliasName-update', function () {
        $('#updateVirtualUsageAlisaName').modal('show');
        var modalTitle = '虚拟用况别名'
        if($(this).parent().attr('virtualUsageGroupId')){
            modalTitle = '虚拟用况组别名'
        }
        $("#updateVirtualUsageAlisaName .modal-title").html("修改"+modalTitle);
        $("#updateVirtualUsageAlisaName .control-label:eq(0)").html(modalTitle);
        $("#updateVirtualUsageAlisaName input[name='updateAlisaName']").attr("placeholder",modalTitle);
        $("#updateVirtualUsageAlisaName input[name='updateAlisaName']").val($(this).parent().attr("description"));
    }).on('click', ".process-conditions-outOfCycle-if-elseif-else,.process-conditions-continueCycle-if-elseif-else", function (e) {
        // 当前分支流程pid
        var pid = $(this).parent().attr('id');
        var isContinueCycle = $(this).attr("class").indexOf("continueCycle")>=0;
        var message = isContinueCycle?"确定继续循环分支么？":"确定跳出循环分支么？";
        var path = isContinueCycle?"saveContinueEnd":"saveBreakEnd";
        $.modal.confirm(message, function () {
            saveBreakEnd(pid, path);
        })
    }).on('click', ".process-conditions-outOfCycle,.process-conditions-continueCycle", function (e) {
        // 当前分支流程pid
        var pid = $(this).parent().attr('pid');
        var isContinueCycle = $(this).attr("class").indexOf("continueCycle")>=0;
        var message = isContinueCycle?"确定继续循环分支么？":"确定跳出循环分支么？";
        var path = isContinueCycle?"saveContinueEnd":"saveBreakEnd";
        $.modal.confirm(message, function () {
            saveBreakEnd(pid, path);
        })
    }).on('click', ".process-conditions-bffUsageParam", function (e) {
        var id = $(this).parent().attr('id');
        // 记录当前页面滚动距离
        window.sessionStorage.setItem('scrolltop',$(window).scrollTop());
        $.modal.openTab("字段来源", prefix + "/bff_usage_params?processBranchId=" + id);
    }).on('click', ".process-conditions-bffUsageGroupParam", function (e) {
        var processBranchId = $(this).parent().attr('id');
        var virtualUsageGroupId = $(this).parent().attr('virtualUsageGroupId');
        // 记录当前页面滚动距离
        window.sessionStorage.setItem('scrolltop',$(window).scrollTop());
        $.modal.openTab("字段来源", ctx + "virtualUsageGroup/virtualUsageGroup/edit?id=" + virtualUsageGroupId + "&processBranchId=" + processBranchId);
    }).on('click', ".process-conditions-virtualUsage-update", function (e) {
        var virtualUsageId = $(this).parent().attr('virtualUsageId');
        // 记录当前页面滚动距离
        window.sessionStorage.setItem('scrolltop',$(window).scrollTop());
        $.modal.openTab("虚拟用况接口编辑", ctx + "interface/interface/bff_usage_params/" + virtualUsageId);
    }).on('click', ".process-conditions-virtualUsageGroup-update", function (e) {
        var virtualUsageGroupId = $(this).parent().attr('virtualUsageGroupId');
        // 记录当前页面滚动距离
        window.sessionStorage.setItem('scrolltop',$(window).scrollTop());
        $.modal.openTab("虚拟用况组编辑", ctx + "virtualUsageGroup/virtualUsageGroup/edit?id=" + virtualUsageGroupId);
    }).on('click', ".process-conditions-else", function () {
        // 当前分支流程信息
        var pid = $(this).parent().attr('pid');
        var sortNum = $(this).parent().attr('sortNum');
        // 设置分支流程条件
        var params = {};
        params.interfaceId = interfaceId;
        params.parentProcessBranchId = pid;
        params.processEndFlag = "N";
        params.sortNum = parseInt(sortNum) + 1;
        var processBranchCondition = {};
        processBranchCondition.type = "else";
        params.processBranchCondition = processBranchCondition;
        saveCondition(params);
    }).on('click', ".process-conditions-else-error", function () {
        //当前分支流程信息
        var pid = $(this).parent().attr('pid');
        var sortNum = $(this).parent().attr('sortNum');
        // 设置分支流程条件
        var params = {};
        params.interfaceId = interfaceId;
        params.parentProcessBranchId = pid;
        params.processEndFlag = "Y";
        params.sortNum = parseInt(sortNum) + 1;
        var processBranchCondition = {};
        processBranchCondition.type = "else";
        params.processBranchCondition = processBranchCondition;
        $.modal.confirm("确定设置异常结束么？", function () {
            saveCondition(params);
        })
    }).on('click', ".process-conditions-else-error-no-else", function () {
        // 当前分支流程信息
        var id = $(this).parent().attr('id');
        $.modal.confirm("确定设置流程异常结束么？", function () {
            saveExceptionEnd(id);
        })
    }).on('click', ".process-conditions-end", function () {
        // 当前分支流程pid
        var pid = $(this).parent().attr('pid');
        // 流程结束
        $.modal.confirm("确定设置流程结束么？", function () {
            saveConditionEnd(pid);
        })
    }).on('click', ".process-conditions-end-if-elseif-else", function () {
        // 当前分支流程id
        var id = $(this).parent().attr('id');
        // 流程结束
        $.modal.confirm("确定设置流程结束么？", function () {
            saveConditionEnd(id);
        })
    }).on('click', ".process-conditions-delete", function () {
        // 当前分支流程id
        var id = $(this).parent().attr('id');
        // 流程删除
        $.modal.confirm("确定删除该流程分支么？", function () {
            deleteProcessBranch(id);
        })
    }).on('click', ".set-error-code", function () {
        var entityId = $(this).parent().attr('entityid')||0;
        console.log(entityId)
        var title = "设错误码";
        var url = ctx + "processBranchEnd/processBranchEnd/select/"+entityId;
        var width = 800;
        var height = $(window).height() - 200;
        $.modal.open(title, url, width, height);
    }).on('click', ".navtabs a[data-toggle='tab']", function () {
        var action = $(this).data("action");
        $("[data-toggle='popover']").popover('hide');
        if (action) {
            window[action]();
        }
    }).on('click', ".check-process-condition", function () {
        var action = $(".nav-tabs>li.active a").data("action");
        if (action) {
            window[action]();
        }
    }).on('click', ".show-popover,.ellipsis", function (e) {
        $("input[name='processBranchId']").val($(this).data("id"));
        $("input[name='parentProcessBranchId']").val($(this).data("pid"));
        $("input[name='sortNum']").val($(this).data("sortnum"));
        $("input[name='processBranchName']").val($(this).siblings(".content-txt").html());
        // 记录当前页面滚动距离
        window.sessionStorage.setItem('scrolltop',$(window).scrollTop())
        e.stopPropagation()
    }).on('click', ".delCondition", function () {
        $(this).parents("tr").remove();
        for (var i = 0; i < $(".process-conditions-model tbody tr").length; i++) {
            $(`.process-conditions-model tbody tr:eq(${i}) td:nth-child(2)`).html(i + 1);
        }
        addGroup();
    }).on('change', ".group-select", function () {
        addGroup();
    }).on('change', ".branchConditionDetailDictCode-select", function () {
        // 根据模式显示对象类型
        let parentObj = $(this).parents("tr");
        parentObj.find(".contractValueTd").find(".contractValue-select,.contractType-select,input").remove();
        parentObj.find(".contractValueTd").find(".contractValue").show();
        if($(this).val()==3){
            parentObj.find(".obj1-select").hide();
            parentObj.find(".ObjSelect").empty();
        }else{
            parentObj.find(".obj1-select").val(0).trigger("change");
            parentObj.find(".obj1-select").show();
            if($(this).val()==1){
                parentObj.find(".obj1-select option").show();
                parentObj.find(".obj1-select option:eq(2)").hide()
            }else{
                parentObj.find(".obj1-select option").hide();
                parentObj.find(".obj1-select option:eq(0),.obj1-select option:eq(2)").show();
            }
        }
    }).on('change', ".interface-select", function () {
        var parentDom = $(this).parents("tr");
        var ranchConditionDetailDictCode = parentDom.find("select[name='branchConditionDetailDictCode']").val();
        ranchConditionDetailDictCode!=3 && parentDom.find(".obj1-select").trigger("change");
    }).on('change', ".obj1-select", function () {
        // 请选择不联动
        if($(this).val()!=0){
            queryFieldList($(this).val(), $(this));
            queryEnum(0,'N',$(this))
        }else{
            $(this).siblings(".ObjSelect").empty();
        }
    }).on('change', ".obj2-select,.obj3-select", function () {
        //字段类型第二个联动处理
        $(this).attr("class").indexOf("obj2-select")>=0 && $(this).data("type") == 3 && queryParamFieldList($(this).val(), $(this));
        let{isfieldenum, dictid} = $(this).find("option:selected").data();
        queryEnum(dictid,isfieldenum,$(this))
    }).on('hide.bs.modal', "#addVirtualUsage, #processConditions", function () {
        $(this).remove();
        $('.wrapper-content').after(window[$(this).attr("id") + 'Modal']);
    }).on('shown.bs.popover',"[data-toggle='popover']",function () {
       if(popoverView != this){
           $(popoverView).popover('hide');
           $(popoverView).show();
       }
        popoverView = this;
    }).on("click",".popover-content ul>li,.add-popover-tit",function () {
        $("[data-toggle='popover']").popover('hide');
    }).on("click","#treeRootByName li,#treeRootByStory li",function (e) {
        let {desc, color} = $(this).data();
        if(!(desc=='else' || color=='green')){
            getProcessBranchDetail($(this).data());
        }
        e.stopPropagation();
    }).on("change",'.condition-select',function(){
        if(noContractValues.indexOf($(this).val())<0){
            if($(this).parents("tr").find(".contractValue-select").length>0){
                $(this).parents("tr").find(".contractValue-select").show();
            }else{
                $(this).parents("tr").find(".contractValue").show();
            }
        }else{
            $(this).parents("tr").find(".contractValue,.contractValue-select").hide();
        }
    }).on("click",'.expand-children', function (e) {
        var childId = $(this).data("id");
        $(".childList"+childId)[$(".childList"+childId).css('display')=='none'?'show':'hide']();
        e.stopPropagation();
    }).on('change', ".dictCategory-select", function (e) {
        queryDictType($(this),$(this).val());
    }).on('change', ".dictType-select", function (e) {
        queryDict($(this),$(this).val());
    }).on('change', ".branchCondition", function (e) {
        var id = $(this).data("id");
        var index = groupSelectedList.findIndex((item)=>item.branchConditionGroupId == id);
        if(index>=0){
            groupSelectedList[index]['joinCondition'] = $(this).val()
        }else{
            groupSelectedList.push({branchConditionGroupId:id,joinCondition:$(this).val()})
        }
    })
    //跳转到特定的位置
    function scrollToPosition() {
        $('html, body').animate({
            scrollTop: window.sessionStorage.getItem("scrolltop")
        }, 500);
    }
    /**
     * 添加条件
     */
    function addCondition() {
        // 添加条件
        var addConditionTplHtml = $("#addConditionTpl").html();
        laytpl(addConditionTplHtml).render({
            conditionDictList: conditionDictList,
            dictCategoryList:dictCategoryList,
            interfaceList:interfaceList}, function (html) {
            $(".process-conditions-model tbody").append(html);
        });
        $("[data-toggle='popover']").popover();
        var length = $(".process-conditions-model tbody tr").length;
        $(`.process-conditions-model tbody tr:eq(${length - 1}) td:nth-child(2)`).html(length)
        // 添加组名称
        addGroup();
    }

    /**
     * 添加组名称
     */
    function addGroup(list) {
        list = list || [];
        if(list.length==0){
            $(".group-select").each(function (e) {
                list.push(Object.assign({},{branchConditionGroupId:$(this).val()}))
            })
            // 存在数据
            if(groupSelectedList){
                list.forEach(e=>{
                    var item = groupSelectedList.find((item)=>e.branchConditionGroupId == item.branchConditionGroupId);
                    if(item){
                        e.joinCondition = item.joinCondition;
                    }
                })
            }
        }
        // 去重
        list =  list.filter((item,index) =>{
            return list.findIndex(item1 =>item1.branchConditionGroupId==item.branchConditionGroupId) == index
        })
        var groupInfoTplHtml = $("#groupInfoTpl").html();
        laytpl(groupInfoTplHtml).render(list, function (html) {
            $(".modal-footer .groupList").html(html);
        });
    }
    function obj1Select(value,parentObj){
        if(value==1){
            parentObj.find(".obj1-select option").show();
            parentObj.find(".obj1-select option:eq(2)").hide()
        }else{
            parentObj.find(".obj1-select option").hide();
            parentObj.find(".obj1-select option:eq(2)").show();
        }
    }
    /**
     *  获取流程分支编排， by接口名称
     *  @params conditionFlag 1-只看流程条件 2-全部
     */
    function queryProcessBranch(isAgain) {
        isAgain = isAgain || false;
        var conditionFlag = $(".check-process-condition").prop("checked");
        let config = {
            url: prefix + "/queryProcessBranch",
            type: "get",
            dataType: "json",
            data: {
                "interfaceId": interfaceId,
                "conditionFlag": conditionFlag ? 1 : 2
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    $("#treeRootByName").empty();
                    processTree(result.data || [], $("#processBranchNodeByNameTpl"), $("#treeRootByName"));
                    $("[data-toggle='popover']").popover({
                        html: true
                    });
                    return false;
                    isAgain && scrollToPosition();
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     *  获取流程分支编排，by 步骤故事
     *  @params conditionFlag 1-只看流程条件 2-全部
     */
    function queryProcessBranchStory(isAgain) {
        isAgain = isAgain || false;
        var conditionFlag = $(".check-process-condition").prop("checked");
        let config = {
            url: prefix + "/queryProcessBranchStory",
            type: "get",
            dataType: "json",
            data: {
                "interfaceId": interfaceId,
                "conditionFlag": conditionFlag ? 1 : 2
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    $("#treeRootByStory").empty();
                    processTree(result.data || [], $("#processBranchNodeByStoryTpl"), $("#treeRootByStory"));
                    $("[data-toggle='popover']").popover({
                        html: true
                    });
                    return false;
                    isAgain && scrollToPosition();
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 流程编排树结构
     * @param data
     * @param dom
     */
    var enToChinese = {"if":"如果","elseif":"再者如果","else":"否则","and":"并且","or":"或者"}
    function processTree(data, tplDom, divDom) {
        data.forEach(function (e) {
            var processNodeTplHtml = tplDom.html();
            if(e.processBranchName) {
                e.processBranchNameDom = e.processBranchName.replace(/(if|and|or|elseif|else)/g, function (rs) {
                    return `<span class="specialFlag">${rs}<\/span>`;
                });
            }
            if(e.processBranchDescription){
                e.processBranchDescription = e.processBranchDescription.replace(/(if|and|or|elseif|else)/g,function (rs){
                    return `<span class="specialFlag">${enToChinese[rs]}<\/span>`;
                });
            }
            laytpl(processNodeTplHtml).render(e || {}, function (html) {
                divDom.append(html);
            });
            if (e.children != null && e.children.length > 0) {
                processTree(e.children, tplDom, $(".childList" + e.processBranchId));
            }
        });
    }

	/**
	 *  查询接口列表
	 */
	function queryInterfaceList() {
		// 流程分支id
		var processBranchId = $("input[name='processBranchId']").val();
		var config = {
			url: prefix + "/queryInterfaceList",
			type: "get",
			dataType: "json",
            async:false,
			data: {
				"interfaceId": interfaceId,
				"processBranchId": processBranchId
			},
			beforeSend: function () {
				$.modal.loading("正在处理中，请稍后...");
			},
			success: function (result) {
				$.modal.closeLoading();
				if (result.code == web_status.SUCCESS) {
					interfaceList = result.data;
					return false;
				}
				if (result.code == web_status.WARNING) {
					$.modal.alertWarning(result.msg)
					return false;
				}
				$.modal.alertError(result.msg);
			}
		};
		$.ajax(config);
	}
	/**
	 *  查询流程分支详情
	 */
	function getProcessBranchDetail(params) {
        // 流程分支id
	    var processBranchId = params ? params.id : $("input[name='processBranchId']").val();
		var config = {
			url: prefix + "/getProcessBranchDetail",
			type: "get",
			dataType: "json",
			data: {
				"processBranchId": processBranchId
			},
			beforeSend: function () {
				$.modal.loading("正在处理中，请稍后...");
			},
			success: function (result) {
				$.modal.closeLoading();
				if (result.code == web_status.SUCCESS) {
				    // 点击之后显示右侧
				    if(params){
                        var rightPartTplHtml = $("#rightPartTpl").html();
                        var rightPartData = result.data.processBranchCondition
                            ? result.data.processBranchCondition
                            : result.data.processBranchEnd
                                ? result.data.processBranchEnd
                                : result.data;
                        rightPartData.color = params.color;
                        // 虚拟用况
                        if (params.color == 'blue') {
                            var fieldSourceVoList = result.data.fieldSourceVoList;
                            fieldSourceVoList.forEach(function (e) {
                                var mappingDescArr = [];
                                mappingDescArr.push("入参");
                                // 字段
                                if (1 == e.objectType) {
                                    mappingDescArr.push(e.fieldName);
                                    mappingDescArr.push("(");
                                    mappingDescArr.push(e.fieldEnName);
                                    mappingDescArr.push(")");
                                    mappingDescArr.push("字段映射");
                                    mappingDescArr.push(e.sourceInterfaceName);
                                    mappingDescArr.push("接口来源的");
                                    if (1 == e.sourceObjectType) {
                                        mappingDescArr.push(e.sourceFieldName);
                                        mappingDescArr.push("(");
                                        mappingDescArr.push(e.sourceFieldEnName);
                                        mappingDescArr.push(")");
                                        mappingDescArr.push("字段");
                                    } else {
                                        mappingDescArr.push(e.sourceParamsName);
                                        mappingDescArr.push("(");
                                        mappingDescArr.push(e.sourceParamsEnName);
                                        mappingDescArr.push(")");
                                        mappingDescArr.push("数据集下");
                                        mappingDescArr.push(e.sourceFieldName);
                                        mappingDescArr.push("(");
                                        mappingDescArr.push(e.sourceFieldEnName);
                                        mappingDescArr.push(")");
                                        mappingDescArr.push("字段");
                                    }
                                } else {
                                    mappingDescArr.push(e.paramsName);
                                    mappingDescArr.push("(");
                                    mappingDescArr.push(e.paramsEnName);
                                    mappingDescArr.push(")");
                                    mappingDescArr.push("数据集下");
                                    mappingDescArr.push(e.fieldName);
                                    mappingDescArr.push("(");
                                    mappingDescArr.push(e.fieldEnName);
                                    mappingDescArr.push(")");
                                    mappingDescArr.push("字段映射");
                                    mappingDescArr.push(e.sourceInterfaceName);
                                    mappingDescArr.push("接口来源的");
                                    if (1 == e.sourceObjectType) {
                                        mappingDescArr.push(e.sourceFieldName);
                                        mappingDescArr.push("(");
                                        mappingDescArr.push(e.sourceFieldEnName);
                                        mappingDescArr.push(")");
                                        mappingDescArr.push("字段");
                                    } else {
                                        mappingDescArr.push(e.sourceParamsName);
                                        mappingDescArr.push("(");
                                        mappingDescArr.push(e.sourceParamsEnName);
                                        mappingDescArr.push(")");
                                        mappingDescArr.push("数据集下");
                                        mappingDescArr.push(e.sourceFieldName);
                                        mappingDescArr.push("(");
                                        mappingDescArr.push(e.sourceFieldEnName);
                                        mappingDescArr.push(")");
                                        mappingDescArr.push("字段");
                                    }
                                }
                                e.mappingDesc = mappingDescArr.join(" ");
                            });
                        }
                        laytpl(rightPartTplHtml).render(rightPartData, function (html) {
                            $(".right-part").html('')
                            $(".right-part").append(html);
                        });
                        if(params.color=='blue'){
                            loadInterfaceParams(result.data.entityId)
                        }
                        return false;
                    }
                    let {processBranchCondition, sortNum, processEndFlag} = result.data;
                    $("input[name='modalProcessBranchId']").val(processBranchCondition.processBranchId);
                    $(".join-condition").val(processBranchCondition.joinCondition);
                    $(".branchConditionDesc").val(processBranchCondition.branchConditionDesc);
                    var editConditionTplHtml = $("#editConditionTpl").html();
                    laytpl(editConditionTplHtml).render({
                        conditionDictList: conditionDictList,
                        interfaceList:interfaceList,
                        dictCategoryList: dictCategoryList,
                        processBranchConditionDetailList:processBranchCondition.processBranchConditionDetailList
                    }, function (html) {
                        $(".process-conditions-model tbody").append(html);
                    });
                    processBranchCondition.processBranchConditionDetailList.forEach(function(e,index){
                        if(e.contractDictCategory){
                            queryDictType($("tbody tr:eq("+index+") .dictCategory-select"),e.contractDictCategory,e.contractDictType);
                            queryDict($("tbody tr:eq("+index+") .dictType-select"),e.contractDictType,e.contractValue);
                        }
                        if(e.branchConditionDetailDictCode==3){
                            $("tbody tr:eq("+index+")").find(".obj1-select").hide();
                            $("tbody tr:eq("+index+")").find(".ObjSelect").empty();
                        }else{
                            queryFieldList(e.objectType, $("tbody tr:eq("+index+") .obj1-select"),e.objectId);
                            e.objectType == 3 && queryParamFieldList(e.objectId, $("tbody tr:eq("+index+") .obj2-select"), e.paramsId);
                            var selectDom = $("tbody tr:eq("+index+") .obj2-select")
                            if(e.objectType == 3){
                                //数据集字段
                                selectDom = $("tbody tr:eq("+index+") .obj3-select");
                            }
                            let{ isfieldenum, dictid } = selectDom.find("option:selected").data()||{};
                            queryEnum(dictid, isfieldenum,selectDom,e.contractValue);
                        }
                        // 约定值隐藏逻辑
                        if(noContractValues.indexOf(e.judgeConditionDictCode)>=0){
                            $("tbody tr:eq("+index+") .condition-select").val(e.judgeConditionDictCode).trigger("change");
                        }
                        groupSelectedList.push(Object.assign({},{branchConditionGroupId:e.branchConditionGroupId,joinCondition:e.joinCondition}))

                    })
                    processEndFlag && $('.processEndFlag').attr("checked",true);
                    groupSelectedList =  groupSelectedList.filter((item,index) =>{
                        return groupSelectedList.findIndex(item1 =>item1.branchConditionGroupId==item.branchConditionGroupId) == index
                    });
                    addGroup(groupSelectedList)
                    $("input[name='sortNum']").val(sortNum);
					return false;
				}
				if (result.code == web_status.WARNING) {
					$.modal.alertWarning(result.msg)
					return false;
				}
				$.modal.alertError(result.msg);
			}
		};
		$.ajax(config);
	}

	function usageParamsMappingHandle(data) {

    }
    /**
     *  查询字段接口，
     *  @params type 1-字段 2-数据集
     */
    function queryFieldList(type, dom, selectId) {
        if(type==0){
            return false;
        }
        selectId = selectId ||"";
        // 接口类型
		var interfaceId = dom.parent().prev().find(".interface-select").val();
        var interfaceType = dom.parent().prev().find(".interface-select option:selected").data("interfacetype");
        var config = {
            url: prefix + "/queryFieldList",
            type: "get",
            dataType: "json",
            async:false,
            data: {
                "type": type == 3 ? 2 : type,
                "interfaceId": interfaceId,
                "interfaceType": interfaceType
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    var selectTplHtml = $("#selectTpl").html();
                    result.prefix = 2
                    result.type = type
                    result.selectId= selectId
                    laytpl(selectTplHtml).render(result, function (html) {
                        dom.siblings(".ObjSelect").empty();
                        dom.siblings(".ObjSelect").append(html);
                    });
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 查询数据集字段接口
     */
    function queryParamFieldList(id, dom, selectId) {
        selectId = selectId ||"";
        let config = {
            url: prefix + "/queryParamFieldList",
            type: "get",
            dataType: "json",
            async:false,
            data: {
                "id": id
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    var selectTplHtml = $("#selectTpl").html();
                    result.prefix = 3
                    result.selectId= selectId
                    laytpl(selectTplHtml).render(result, function (html) {
                        dom.siblings(".obj3-select").length==1 && dom.siblings(".obj3-select").remove()
                        dom.after(html);
                    });
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 查询判断条件
     */
    function getConditionDictList() {
        let config = {
            url: prefix + "/conditionDictList",
            type: "get",
            dataType: "json",
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    conditionDictList = result.data
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 保存流程分支条件
     */
    function saveCondition(params) {
        var config = {
            url: prefix + "/saveCondition",
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(params),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    $('#processConditions').modal('hide')
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 设置else分支异常结束
     * @params parentProcessBranchId 父流程id
     */
    function saveExceptionEnd(parentProcessBranchId) {
        var params = {};
        params.interfaceId = interfaceId;
        params.parentProcessBranchId = parentProcessBranchId;
        var config = {
            url: prefix + "/saveExceptionEnd",
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(params),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 保存流程分支条件
     */
    function saveConditionEnd(parentProcessBranchId) {
        var params = {};
        params.interfaceId = interfaceId;
        params.parentProcessBranchId = parentProcessBranchId;
        var config = {
            url: prefix + "/saveEnd",
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(params),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 删除流程分支
     * @params processBranchId 流程分支id
     */
    function deleteProcessBranch(processBranchId) {
        let config = {
            url: prefix + "/delete",
            type: "get",
            dataType: "json",
            data: {
                "processBranchId": processBranchId
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    // 重新加载流程分支树
                    $(".popover").hide();
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 接口虚拟用况
     */
    function bffVirtualUsageList() {
        var params = {};
        params.interfaceId = interfaceId;
        var config = {
            url: ctx + "interface/interface/virtualUsageList",
            type: "post",
            dataType: "json",
            data: params,
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    virtualUsageList = result.data || [];
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config);
    }

    /**
     * 接口虚拟用况
     */
    function bffVirtualUsageGroupList() {
        var params = {};
        params.interfaceId = interfaceId;
        var config = {
            url: prefix + "/queryVirtualUsageGroup",
            type: "post",
            dataType: "json",
            data: params,
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    virtualUsageGroupList = result.data || [];
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config);
    }

    function saveVirtualUsageAlisaName() {
        var params = {};
        params.processBranchId = $("input[name='processBranchId']").val()
        params.aliasName = $("input[name='updateAlisaName']").val();
        var config = {
            url: prefix + "/edit",
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(params),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    $('#updateVirtualUsageAlisaName').modal('hide')
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }
    /**
     * 保存流程分支虚拟用况
     * @params type =1 虚拟用况  type =4 虚拟用况组
     */
    function saveVirtualUsage(type) {
        var params = {};
        params.type = type;
        params.interfaceId = interfaceId;
        params.entityId = type == 1 ? $("#virtualUsageId").val() : $("#virtualUsageGroupId").val();
        // 虚拟用况/用况组下添加用况父级节点
        var preProcessBranchId = $("input[name='preProcessBranchId']").val();
        // if elseif else 分支添加新增虚拟用况/组增加sortNum字段
        if(!preProcessBranchId) {
            params.sortNum = 0;
        }
        params.parentProcessBranchId = preProcessBranchId || $("input[name='processBranchId']").val() || '';
        // 无上级节点  parentProcessBranchId值为空
        if(preProcessBranchId == $("input[name='processBranchId']").val()){
            params.parentProcessBranchId = '';
        }
        params.processEndFlag = $('.process-end').prop("checked") ? 'Y' : 'N';
        preProcessBranchId && (params.preProcessBranchId = $("input[name='processBranchId']").val() || '');

        if($("input[name='outSortNum']").val()){
            params.sortNum = $("input[name='outSortNum']").val();
            params.preProcessBranchId = '';
        }
        var aliasName = type==1?'alisaName':'groupAlisaName';
        params.aliasName = $("input[name='"+aliasName+"']").val();
        var config = {
            url: prefix + "/saveVirtualUsage",
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(params),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    $("input[name='outSortNum']").val('');
                    type == 1 ? $('#addVirtualUsage').modal('hide') : $('#addVirtualUsageGroup').modal('hide');
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 查询字段枚举
     */
    function queryEnum(dictId,isfieldenum,dom,selectId) {
        selectId = selectId||'';
        var judgeConditionDictCode = dom.parents("tr").find(".condition-select").val();
        if(isfieldenum!='Y'){
            dom.parents("tr").find(".contractValueTd .contractValue-select").remove();
            dom.parents("tr").find(".contractValueTd .contractValue")[noContractValues.indexOf(judgeConditionDictCode)>=0?'hide':'show']();
            return false
        }
        let config = {
            url: prefix + "/queryEnum",
            type: "get",
            dataType: "json",
            data:{"dictId":dictId},
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    var list = result.data || [];
                    if (result.code == web_status.SUCCESS) {
                        var selectFieldEnumTplHtml = $("#selectFieldEnumTpl").html();
                        result.selectId= selectId
                        laytpl(selectFieldEnumTplHtml).render(result, function (html) {
                            dom.parents("tr").find(".contractValueTd .contractValue-select").remove();
                            dom.parents("tr").find(".contractValueTd .contractValue").hide().after(html);
                            dom.parents("tr").find(".contractValueTd .contractValue-select")[noContractValues.indexOf(judgeConditionDictCode)>=0?'hide':'show']();
                        });
                        return false;
                    }
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }

    /**
     * 保存流程分支虚拟用况
     */
    function saveErrorCode() {
        var params = {};
        params.interfaceId = interfaceId;
        params.entityId = $("#virtualUsageId").val();
        params.parentProcessBranchId = $("input[name='processBranchId']").val() || '';
        params.processEndFlag = $('.process-end').prop("checked") ? 'Y' : 'N';
        var config = {
            url: ctx + "errorCode/errorCode/save",
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(params),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    $('#addVirtualUsage').modal('hide')
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }
    /**
     *根据结束Id获取错误码信息
     */
    function editBranchEndErrorCode(params) {
        let config = {
            url: ctx + "processBranchEnd/processBranchEnd/edit",
            type: "post",
            data: params,
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    return false;
                }
                if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                    return false;
                }
                $.modal.alertError(result.msg);
            }
        };
        $.ajax(config);
    }
    /**
     * 加载 接口参数
     */
    function loadInterfaceParams(id) {
        var config = {
            url: ctx + "interface/interface/paramList",
            type: "post",
            dataType: "json",
            data: "interfaceType=3&interfaceId="+id,
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function(result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    var resultJson = result.data;
                    if(!resultJson) {
                        return false;
                    }
                    data = resultJson || [];
                    var contentPreviewTplHtml = $("#contentPreviewTpl").html();
                    convertResponse(data);
                    laytpl(contentPreviewTplHtml).render(data, function (html) {
                        $("#content-preview").empty();
                        $("#content-preview").html(html);
                    });
                    $(".right-part .title").html(data.interfaceInfo.interfaceName)
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config);
    }

    /**
     * 跳出循环分支
     */
    function saveBreakEnd(parentProcessBranchId,path) {
        path = path || 'saveBreakEnd'
        var config = {
            url: prefix + "/"+path,
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify({
                interfaceId:interfaceId,
                parentProcessBranchId:parentProcessBranchId=='0'?null:parentProcessBranchId
            }),
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function(result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    $(".popover").hide();
                    // 重新加载流程分支树
                    var action = $(".nav-tabs>li.active a").data("action");
                    if (action) {
                        window[action](true);
                    }
                    return false;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config);
    }

    /**
     * 获取字典分类
     * @param selectObj
     */
    var dictCategoryList = [];
    function  getDictCategory(selectObj) {
        var config = {
            url: ctx + "frontInterfaceFieldSource/frontInterfaceFieldSource/getDictCategory",
            type: "get",
            dataType: "json",
            async:false,
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function(result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    dictCategoryList = result.data;
                }
            }
        };
        $.ajax(config);
    }

    /**
     * 获取字典类型
     * @param selectObj
     */
    function queryDictType(dom,category,contractDictType){
        if(!category){
            return false;
        }
        var config = {
            url: ctx + "frontInterfaceFieldSource/frontInterfaceFieldSource/getDictListByCategory",
            type: "get",
            dataType: "json",
            async:false,
            data:{
                category:category
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function(result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    var queryDictTypeOptionTplHtml = $("#queryDictTypeOptionTpl").html();
                    if(contractDictType){
                        result.contractDictType = contractDictType;
                    }
                    laytpl(queryDictTypeOptionTplHtml).render(result, function (html) {
                        dom.siblings(".dictType-select").remove();
                        dom.after(html);
                    });
                }
            }
        };
        $.ajax(config);
    }
    /**
     * 获取字典值
     * @param dictType
     */
    function queryDict(dom,dictType,contractValue) {
        if(!dictType){
            return false;
        }
        var config = {
            url: ctx + "frontInterfaceFieldSource/frontInterfaceFieldSource/queryDict",
            type: "post",
            dataType: "json",
            data: {
                dictType:dictType,
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function(result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    var queryDictOptionTplHtml = $("#queryDictOptionTpl").html();
                    if(contractValue){
                        result.contractValue = contractValue;
                    }
                    laytpl(queryDictOptionTplHtml).render(result, function (html) {
                        dom.siblings(".contractValue-select").remove();
                        dom.after(html);
                    });
                }
            }
        };
        $.ajax(config);
    }

</script>
</body>
</html>
